﻿//-----------------------------------------------------------------------
// <copyright file="ISessionHost.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using System.Collections.Generic;
using GateShift.Services.SDK.Services.Events;
using GateShift.Services.SDK.Services.HostIntegration;

#endregion

namespace GateShift.Services.SDK.Services.Hosts
{
    /// <summary>
    /// Direct interface into the manager for sessions
    /// </summary>
    public interface ISessionHost
    {
        /// <summary>
        /// Event raised when a session is disconnected
        /// </summary>
        event EventHandler<ClientSessionEventArgs> SessionDisconnected;

        /// <summary>
        /// Event raised when a session is connected
        /// </summary>
        event EventHandler<ClientSessionEventArgs> SessionConnected;

        /// <summary>
        /// Gets a specific IClientSession by Session ID
        /// </summary>
        /// <param name="sessionID">Session ID to retrieve</param>
        /// <returns>IClientSession found or null if session was not found</returns>
        IClientSession GetSession(Guid sessionID);

        /// <summary>
        /// Gets a list of IClientSession for all sessions currently active
        /// </summary>
        /// <returns>List of client sessions for all sessions</returns>
        IList<IClientSession> GetSession();

        /// <summary>
        /// Checks whether or not a requested IClientSession exists
        /// </summary>
        /// <param name="sessionID">Session ID to check</param>
        /// <returns>Boolean based on the existance of Session ID</returns>
        bool SessionExists(Guid sessionID);

        /// <summary>
        /// Registers an IClientDataHandler to handle client data based on the supplied Service ID
        /// </summary>
        /// <param name="serviceID">Service ID to register</param>
        /// <param name="handler">IClientDataHandler to use when the client requests a specific ID</param>
        void RegisterClientDataHandler(byte serviceID, IClientDataHandler handler);

        /// <summary>
        /// Sends Data to a specific client by SessionID
        /// </summary>
        /// <param name="sessionID">Session ID of the client to send data to</param>
        /// <param name="serviceID">Client Service ID to send the data to</param>
        /// <param name="serviceCode">Service Code to reference when sending data</param>
        /// <param name="data">Serialized binary data to send to the client</param>
        /// <param name="encrypt">Whether or not to encrypt the data to the client</param>
        void SendClientData(Guid sessionID, byte serviceID, byte serviceCode, byte[] data, bool encrypt);

        /// <summary>
        /// Sends Data to all clients
        /// </summary>
        /// <param name="serviceID">Client Service ID to send the data to</param>
        /// <param name="serviceCode">Service Code to reference when sending data</param>
        /// <param name="data">Serialized binary data to send to the client</param>
        /// <param name="encrypt">Whether or not to encrypt the data to the client</param>
        void SendClientData(byte serviceID, byte serviceCode, byte[] data, bool encrypt);

        /// <summary>
        /// Sends Data to a list of clients by SessionID
        /// </summary>
        /// <param name="sessionIDs">List of Session IDs of the clients to send data to</param>
        /// <param name="serviceID">Client Service ID to send the data to</param>
        /// <param name="serviceCode">Service Code to reference when sending data</param>
        /// <param name="data">Serialized binary data to send to the client</param>
        /// <param name="encrypt">Whether or not to encrypt the data to the client</param>
        void SendClientData(List<Guid> sessionIDs, byte serviceID, byte serviceCode, byte[] data, bool encrypt);

        /// <summary>
        /// Disconnects the specified client
        /// </summary>
        /// <param name="sessionID">Session ID of the client to disconnect</param>
        void DisconnectClient(Guid sessionID);
    }
}